using Android.Content;
using SQLite;
using CapstoneProject.Models;
using System.Collections.Generic;

namespace CapstoneProject.DataAccess
{
    public class OrmUserRepository : IUserRepository
    {
        private UserDatabaseHelper helper;

        public OrmUserRepository(Context context)
        {
            helper = new UserDatabaseHelper(context);
        }

        public IList<User> GetAllUsers()
        {
            using (var database = new SQLiteConnection(helper.WritableDatabase.Path))
            {
                IList<User> userlist = new List<User>();
                foreach (User u in database.Table<User>())
                {
                    userlist.Add(u);
                }
                return userlist;
            }
        }

        public long AddUser(string username, string password)
        {
            using (var database = new SQLiteConnection(helper.WritableDatabase.Path))
            {
                return database.Insert(new User
                {
                    Username = username,
                    Password = password
                });
            }
        }
    }
}